package com.macrog.controller;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * Created by guohong on 2018/7/12.
 */
@RestController
public class RabbitMqController {

    @Autowired
    AmqpTemplate amqpTemplate;

    @RequestMapping("/test1")
    public String test1() {
        List<Map<String, Object>> list=new ArrayList<>();
        Map<String, Object> map= new HashMap<>();
        map.put("name", "guohong");
        map.put("age", 18);
        map.put("time", new Date());
        list.add(map);

        //第一个参数为routingKey,第二个参数为发送的数据，方法把java对象转成json字符串，再转成字节数组，封装成message发送
        amqpTemplate.convertAndSend("spring_queue_test_01_key", list);

        System.out.println("msg send ok");

        return "SUCCESS";
    }
}
